﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ERPForms
{
    public partial class CursValutarFrm : FrmRezumat
    {
        public Int16 CodValuta = -1;
        public Int16 IdBancaSelectata = -1;
        public DateTime Data = DateTime.MinValue;

        public CursValutarFrm(ModuleClass mc): base(mc)
        {
            InitializeComponent();
            workConnString = mc.workConnectionString;
            eSRPDataSetValute.ValutaCurs.DataColumn.DefaultValue = DateTime.Now;
        }

        public CursValutarFrm(ModuleClass mc,Int16 _CodValuta,Int16 _IdBanca,DateTime _data)
            : base(mc)
        {
            InitializeComponent();
            workConnString = mc.workConnectionString;
            eSRPDataSetValute.ValutaCurs.DataColumn.DefaultValue = DateTime.Now;
            CodValuta = _CodValuta;
            IdBancaSelectata = _IdBanca;
            Data = _data;
        }


        private void CursValutarFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.banciTableAdapter.Connection = con;
            this.banciTableAdapter.Fill(this.eSRPDataSetValute.Banci);
            this.valutaTableAdapter.Connection = con;
            this.valutaTableAdapter.Fill(this.eSRPDataSetValute.Valuta);
            this.valutaCursTableAdapter.Connection = con;
            this.valutaCursTableAdapter.Fill(this.eSRPDataSetValute.ValutaCurs);
            InchideConexiune(con);

            AddBindingSource(valutaCursBindingSource);
            AddTableAdaptor(valutaCursTableAdapter.Adapter);

            AddButton("Valute", global::ERPStudio.Properties.Resources.wallet, Valute, ToolStripItemAlignment.Right, false);
            if (CodValuta != -1)
            {
                denumireCB.SelectedValue = CodValuta;
                ESRPDataSetValute.ValutaCursRow vcr = ((DataRowView)valutaCursBindingSource.AddNew()).Row as ESRPDataSetValute.ValutaCursRow;
                vcr.Data = Data;
                vcr.IDBanca = IdBancaSelectata;
            }
            ActiveControl = valutaCursDGV;
        }

        private void Valute(object sender, EventArgs e)
        {
            ValuteFrm frm = new ValuteFrm(ModuleInfo);
            frm.ShowDialog();
            SqlConnection con = DeschideConexiune(workConnString);
            this.valutaTableAdapter.Connection = con;
            this.valutaTableAdapter.Fill(this.eSRPDataSetValute.Valuta);
            InchideConexiune(con);
        }

       

    }
}
